package com.dish.action;

import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.dish.bean.Dish;
import com.dish.biz.DishService;
import com.dish.utils.JDBCUtils;
import com.dish.utils.MailSender;
import com.dish.utils.PageModel;

@WebServlet("/ShowQuickView")
public class ShowQuickView extends HttpServlet {
	private static final long serialVersionUID = 1L;
       

    public ShowQuickView() {
        super();
        // TODO Auto-generated constructor stub
    }

	private void pageListView(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException, SQLException {

		Dish dih = new Dish();
		Connection conn = null;
		PreparedStatement ps =null;
		ResultSet rs = null;
		String curid = request.getParameter("dishid");
		try {
			conn = JDBCUtils.getConnection();
			ps = conn.prepareStatement("select * from dish where dishid=" + curid);
			rs = ps.executeQuery();
			while(rs != null && rs.next()) {
				dih.setDishid(rs.getInt("dishid"));
				dih.setDishname(rs.getString("name"));
				dih.setDishdesc(rs.getString("description"));
				dih.setImg(rs.getString("img"));
				dih.setPrice(rs.getDouble("price"));
			}
		}catch(RuntimeException e) {
			e.printStackTrace();
		}finally {
			JDBCUtils.free(rs, ps, conn);
		}
		request.setAttribute("fuck",dih);
		RequestDispatcher rd = request.getRequestDispatcher("quickview.jsp");
		rd.forward(request, response);
	}



	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
			
			try {
				pageListView(request, response);
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

	}


	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
